<template>
	<view>
		<view class="" :style="'position: sticky;top: 0;z-index:99;background:#fff;height: '+statusBarHeight+'px;'">
		</view>
		<view class="charge" :style="'top: '+statusBarHeight+'px;'">
			<view class="tabs">
				<image src="../../static/back.png" mode="" @click="back"></image>
				<view class="tabs_right">
					<u-tabs :list="navList" :scrollable='false' keyName="text" lineColor='#5990FF' lineHeight='4'
						lineWidth='18' @click="tabClick"></u-tabs>
				</view>
			</view>
		</view>
		<view class="">
			<view class="inputBox" v-if="tabCurrentIndex=='phone'">
				<view class="inputphone">
					<view class="">{{$t('home.name44')}}</view>
					<input type="number" style="width: 300rpx;margin-left: 30rpx;" v-model="code" maxlength="11"
						placeholder-style="font-size:28rpx" :placeholder="$t('home.name45')+$t('home.name44')" />
				</view>
				<view class="inputbtn" @click="$fun.jump(`/pageA/wallet/walletdetail?id=recharge&name=${$t('home.name46')}`)">{{$t('home.name46')}}
				</view>
			</view>
			<view class="inputBox" v-if="tabCurrentIndex=='video'">
				<view class="inputphone">
					<view class="">{{$t('home.name49')}}</view>
					<input type="number" style="width: 300rpx;margin-left: 30rpx;" v-model="code" maxlength="11"
						placeholder-style="font-size:28rpx" :placeholder="$t('home.name45')+$t('home.name49')" />
				</view>
				<view class="inputbtn" @click="$fun.jump(`/pageA/wallet/walletdetail?id=recharge&name=${$t('home.name46')}`)">{{$t('home.name46')}}
				</view>
			</view>
			<view class="inputlist">
				<block v-for="(item,index) in showList.list" :key="index">
					<view class="itemTitle" :style="index>0?'margin-top:20rpx;':''">
						{{item.title}}
					</view>
					<view class="select_box">
						<view :class="activeIndex==item1.id?'select_item active':'select_item'"
							@click="clickItem(item1,index1)" v-for="(item1,index1) in item.list" :key="index1">
							<text>{{item1.num}}</text>
							<!-- <text>仅售{{item1.money}}</text> -->
						</view>
					</view>
				</block>
			</view>
			<view class="inputlist" v-if="tabCurrentIndex=='phone'">
				<view class="itemTitle">{{$t('home.name47')}}</view>
				<view class="zinput">
					<input type="number" style="width: 580rpx;" placeholder-style="font-size:28rpx"
						:placeholder="$t('home.name45')+','+$t('home.name50')" />
				</view>
			</view>
			<view class="inputlist">
				<view v-html="showList.content">

				</view>
			</view>
			<view class="inputBtn" @click="recharge()">
				{{$t('home.name48')}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				rechargeList: {

				},
				tabCurrentIndex: 'phone',
				activeIndex: 0,
				code: '',
				navList: [
					// {
					// 	state: 'electric',
					// 	text: '电费充值',
					// },
					{
						state: 'phone',
						text: this.$t('home.name42'),
					}, {
						state: 'video',
						text: this.$t('home.name43'),
					},
				],
				showList: []
			}
		},
		onLoad(option) {
			const phoneInfo = uni.getSystemInfoSync(); // 获取手机系统信息
			this.statusBarHeight = phoneInfo.statusBarHeight
			if (!option.name) {
				option.name = '生活缴费'
			}
			console.log(option.name)
			uni.setNavigationBarTitle({
				title: option.name
			})
			this.getRechargeList()
		},
		onNavigationBarButtonTap(e) {
			this.$fun.jump('/pageA/wallet/walletdetail?id=recharge&name=充值记录')
		},
		methods: {
			back() {
				uni.navigateBack()
			},
			// 充值列表
			getRechargeList() {
				this.$fun.ajax.post('Butt/rechargeList', {}).then(res => {
					if (res.code == 1) {
						this.rechargeList = res.data
						this.showList = this.rechargeList.phone;
					}
				})
				// this.$fun.ajax.post('butt/rechargeArea', {}).then(res => {
				// 	if (res.code == 1) {
				// 		// this.rechargeList = res.data
				// 		// this.showList = this.rechargeList.electric;
				// 	}
				// })
			},
			//顶部tab点击
			tabClick(item) {
				this.tabCurrentIndex = item.state;
				this.showList = this.rechargeList[item.state];
				console.log(this.showList)
			},
			// 选择套餐
			clickItem(item, index) {
				this.activeIndex = item.id
				console.log(item)
			},
			recharge() {
				if (!this.code) {
					this.$fun.msg(this.$t('home.name45') +this.$t('home.name44'))
					return
				}
				if (this.activeIndex == null) {
					this.$fun.msg(this.$t('home.name51'))
					return
				}
				if (this.activeIndex == 0 && this.tabCurrentIndex == 'phone') {
					this.$fun.msg(this.$t('home.name52'))
					return
				}
				this.$fun.ajax.post('butt/rechargeCreate', {
					id: this.activeIndex,
					account: this.code,
					type: this.rechargeList[this.tabCurrentIndex].id
				}).then(res => {
					if (res.code == 1) {
						this.$fun.jump(`/pageB/pay?oid=${res.data}`, 2, 0)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #EEF0F5;
	}

	.charge {
		width: 750rpx;
		background: #FFFFFF;
		position: sticky;
		top: 0;
		z-index: 99;

		.tabs {
			height: 88rpx;
			margin-left: 20rpx;
			display: flex;
			align-items: center;

			&_right {
				width: 90%;
			}

			image {
				width: 48rpx;
				height: 48rpx;
			}
		}
	}

	.inputBox {
		display: flex;
		align-items: center;
		margin: 30rpx;

		.inputphone {
			width: 490rpx;
			height: 88rpx;
			background: #FFFFFF;
			border-radius: 24rpx;
			display: flex;
			align-items: center;
			padding: 0 30rpx;
			font-weight: 500;
		}

		.inputbtn {
			width: 180rpx;
			height: 88rpx;
			background: #5990FF;
			border-radius: 24rpx;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
			line-height: 88rpx;
			text-align: center;
			margin-left: 20rpx;
		}
	}

	.inputBtn {
		font-weight: 500;
		font-size: 28rpx;
		color: #FFFFFF;
		width: 690rpx;
		height: 88rpx;
		background: #5990FF;
		border-radius: 44rpx;
		line-height: 88rpx;
		text-align: center;
		margin: 0 auto;
	}

	.inputlist {
		width: 690rpx;
		// height: 368rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		margin: 0 auto 30rpx;
		padding: 30rpx;

		.itemTitle {
			font-weight: 500;
			font-size: 28rpx;
			color: #19181A;
		}

		.select_box {
			display: grid;
			grid-template-columns: 1fr 1fr 1fr;

			.select_item {
				margin-top: 20rpx;
				width: 200rpx;
				height: 120rpx;
				background: #FFFFFF;
				border-radius: 24rpx;
				border: 1rpx solid #CCCCCC;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				font-weight: 500;
				font-size: 32rpx;
				color: #19181A;
			}

			.active {
				border: 2rpx solid #5990FF;
			}


		}

		.zinput {
			width: 630rpx;
			height: 80rpx;
			background: #F6F6F6;
			border-radius: 24rpx;
			padding: 0 20rpx;
			display: flex;
			align-items: center;
			margin-top: 20rpx;
		}
	}

	.cont_positon {
		padding: calc(20rpx + var(--status-bar-height)) 25rpx 0;
		height: calc(100rpx + var(--status-bar-height));
	}

	.head-info {
		position: fixed;
		left: 0;
		top: 0;
		z-index: 10;
		width: 100%;
		/* #ifdef APP-PLUS||H5 */
		padding: calc(20rpx + var(--status-bar-height)) 25rpx 0;
		height: calc(100rpx + var(--status-bar-height));
		/* #endif */
		/* #ifdef MP */
		padding: 0 25rpx;
		height: 170rpx;
		/* #endif */
		// background: url(/static/head_bg1.png) no-repeat;
		// background-size: 100% 433rpx;
		background-color: #FFFFFF;
		overflow: hidden;
		position: relative;

		.bg {
			position: absolute;
			top: 0;
			left: 0;
			z-index: 10;
			width: 100vw;
			height: calc(100rpx + var(--status-bar-height));
		}

		.head-search {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.icon-info {
				display: flex;
				align-items: center;
				height: 100%;
				z-index: 11;

				text {
					font-size: 52rpx;
					color: #f6f6f6;
				}

				image {
					width: 42rpx;
					height: 43rpx;
				}
			}

			.search {
				display: flex;
				align-items: center;
				// width: 100%;
				padding: 0 20rpx;
				height: 65rpx;
				text-align: center;
				justify-content: center;
				z-index: 11;
				// background-color: rgba(255,255,255,0.3);
				// border-radius: 10rpx;
				color: #FFFFFF;

				.icon {
					display: flex;
					align-items: center;
					margin-right: 20rpx;

					image {
						width: 27rpx;
						height: 29rpx;
					}
				}

				.hint {
					display: flex;
					align-items: center;

					.max {
						font-size: 30rpx;
						font-weight: bold;
						color: #FFFFFF;
					}

					.min {
						font-size: 24rpx;
						color: #F6f6f6;
						margin-left: 10rpx;
					}
				}
			}
		}

		.classify-list {
			white-space: nowrap;
			width: 100%;
			height: 100rpx;
			overflow-x: auto;
			overflow-y: hidden;

			.list {
				position: relative;
				display: inline-block;
				width: 20%;
				height: 100%;
				line-height: 100rpx;
				text-align: center;

				text {
					font-size: 28rpx;
					color: #FFFFFF;
					opacity: 0.8;
				}

				.line {
					position: absolute;
					left: 50%;
					bottom: 20rpx;
					width: 60%;
					height: 8rpx;
					background: linear-gradient(to right, #f8f893, #5990FF);
					border-radius: 10rpx;
					transform: translate(-50%, 0);
				}
			}

			.action {
				text {
					font-size: 32rpx;
					opacity: 1;
				}
			}
		}
	}


	.footer-btn {
		position: fixed;
		left: 0;
		bottom: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 100rpx;
		background-color: #FFFFFF;

		.btn {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 80%;
			height: 70rpx;
			background: linear-gradient(to right, $base, $change-clor);
			border-radius: 70rpx;
			box-shadow: 0 10rpx 10rpx $base;

			text {
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
	}

	.navbar {
		display: flex;
		height: 40px;
		padding: 0 5px;
		background: #fff;
		box-shadow: 0 1px 5px rgba(0, 0, 0, .06);
		position: relative;
		z-index: 10;

		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 15px;
			color: $font-color-dark;
			position: relative;

			&.current {
				color: $base-color;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid $base-color;
				}
			}
		}
	}

	// .itemTitle {
	// 	margin-top: 30rpx;
	// 	font-weight: bold;
	// }
</style>